function DegToRad(d) {
    // Converts degrees to radians
    return d * 0.0174532925199432957;
}



var baseDrone = {

    x: 256,
    y: 256,
    angle: 0,
    drawID: 0,

    LTCtr: 0,
    MDCtr: 0,
    HVCtr: 0,

    IDLight: drawList.add("assets/gfx/Drones/LtDrone.png"),
    IDMedium: drawList.add("assets/gfx/Drones/MDDrone.png"),
    IDHeavy: drawList.add("assets/gfx/Drones/HVDrone.png"),

    eatPiece: function (type) {


        switch (type) {
            case 0: this.LTCtr++; break;
            case 1: this.MDCtr++; break;
            case 2: this.HVCtr++; break;
        }


        //**TODO: ADJUST THIS SO YOU TRANSFORM MORE
        if (this.LTCtr > (this.MDCtr + this.HVCtr))
            this.drawID = this.IDLight;

        else if (this.MDCtr > (this.LTCtr + this.HVCtr))
            this.drawID = this.IDMedium;

        else if (this.HVCtr > (this.MDCtr + this.LTCtr))
            this.drawID = this.IDHeavy;



    },

    setRotation: function (old) {

        l2Context.translate(this.x, this.y);
        l2Context.rotate(-old * Math.PI / 180);
        l2Context.rotate(this.angle * Math.PI / 180);
        l2Context.translate(-this.x, -this.y);
    },


    //Have to make the drone act like it's rotated when it draws, but not what it's being controlled

    draw: function (old) {
        l2Context.translate(this.x, this.y);
        l2Context.rotate(-old * Math.PI / 180);
        l2Context.rotate(this.angle * Math.PI / 180);
        l2Context.drawImage(drawList.Img[this.drawID], this.x, this.y);

        l2Context.translate(-this.x, -this.y);


        l2Context.translate(this.x, this.y);
        l2Context.rotate(-this.angle * Math.PI / 180);
        l2Context.translate(-this.x, -this.y);

    },

    update: function () {

        var old = this.angle;

        if (38 in keysDown) { this.y -= 2; this.angle = 270; }
        if (40 in keysDown) { this.y += 2; this.angle = 90; }
        if (37 in keysDown) { this.x -= 2; this.angle = 180; }
        if (39 in keysDown) { this.x += 2; this.angle = 0; }

        //**FOR DEBUG ONLY. TODO: REMOVE ONCE EATING IS FULLY IMPLEMENTED
        if (49 in keysDown) { this.eatPiece(0); } //1 Key
        if (50 in keysDown) { this.eatPiece(1); } //2 Key
        if (51 in keysDown) { this.eatPiece(2); } //3 Key
        if (52 in keysDown) { l2Context.scale(-1, 1); }  //4 Key

        l2Context.x = this.x;
        l2Context.y = this.y;
        //this.draw(old);
        // this.setRotation(old);
    },
    checkCollide: function (collider) {

        if (this.x <= (collider.x + 32)
		&& collider.x <= (this.x + 32)
		&& this.y <= (collider.y + 32)
		&& collider.y <= (this.y + 32))
            return true;
        return false;
    } //End Collide

}


//Initialized
baseDrone.drawID = baseDrone.IDLight;


